//时间格式过滤
template.defaults.imports.formatDate = function (time) {
    let date = new Date(time);
    let y = date.getFullYear();
    let m = date.getMonth() + 1;
    let d = date.getDate();
    return y + '-' + m + '-' + d;
}
//渲染评论列表
function commentRender() {
    $.ajax({

        url: 'admin/comments',
        success: function (res) {
            // console.log(res)
            var html = template('tpl_comments', res)
            $('tbody').html(html)
        },

    })
}
commentRender();
//删除评论
$('tbody').on('click', 'button:contains("删除")', function () {
    let id = $(this).data('id');
    layer.confirm('是否删除?', { icon: 3, title: '提示' }, function (index) {
        //do something

        $.ajax({
            type: 'DELETE',
            url: 'admin/comments/' + id,
            success: function (res) {
                //console.log(res)
                layer.msg(res.message);
                if (res.status === 0) {

                    commentRender();
                }
            }
        })
        layer.close(index);
    });

})

